"""
有一分数序列： 2/1 3/2 5/3 8/5 13/8 21/13......
求出这个数列的前N项之和，保留两位小数。python
"""
def sum_of_fraction_sequence(N):
    # 初始化分子和分母
    numerator, denominator = 2, 1
    total_sum = 0

    for _ in range(N):
        # 加上当前分数
        total_sum += numerator / denominator
        # 更新分子和分母 , 互换
        numerator, denominator = numerator + denominator, numerator

    return round(total_sum, 2)

# 示例：计算前5项之和
N = 5
print(sum_of_fraction_sequence(N))
